package com.ym.core.config;

import com.ym.medical.domain.vo.Node;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 树菜单工具类
 */
public class MenuTreeUtil {
    private List<Node> treeList = null;
    private List<Object> list = new ArrayList<>();


    public List<Object> getMenuList(List<Node> nodeList,Long parentId) {
        this.treeList = nodeList;
        for (Node n : nodeList) {
            Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
            if (n.getParentId().equals(parentId)) {
                mapArr.put("id", n.getId());
                mapArr.put("code", n.getCode());
                mapArr.put("name", n.getName());
                mapArr.put("parentId", n.getParentId());
                mapArr.put("url", n.getUrl());
                mapArr.put("type", n.getType());
                mapArr.put("img", n.getImg());
                mapArr.put("permission", n.getPermission());
                mapArr.put("menuOrder", n.getMenuOrder());
                mapArr.put("childList", menuChild(n.getId()));
                list.add(mapArr);
            }
        }
        return list;

    }


    public List<?> menuChild(Long id) {
        List<Object> lists = new ArrayList<Object>();
        for (Node no : treeList) {
            Map<String, Object> childArray = new LinkedHashMap<String, Object>();
            if (no.getParentId().equals(id)) {
                childArray.put("id", no.getId());
                childArray.put("code", no.getCode());
                childArray.put("name", no.getName());
                childArray.put("parentId", no.getParentId());
                childArray.put("url", no.getUrl());
                childArray.put("type", no.getType());
                childArray.put("img", no.getImg());
                childArray.put("permission", no.getPermission());
                childArray.put("menuOrder", no.getMenuOrder());
                childArray.put("childList", menuChild(no.getId()));
                lists.add(childArray);
            }

        }

        return lists;
    }

}
